package com.example.controller;

import com.example.common.Result;
import com.example.entity.Clazz;
import com.example.entity.Major;
import com.example.service.ClazzService;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/class")
public class ClazzController {
    @Resource
    private ClazzService clazzService;

    @GetMapping("/selectAll")
    public Result selectAll(Clazz clazz){
        List<Clazz> list = clazzService.selectAll(clazz);
        return Result.success(list);
    }

    @GetMapping("/selectPage")
    public Result selectPage(Clazz clazz,
                             @RequestParam(defaultValue = "1") Integer pageNum,
                             @RequestParam(defaultValue = "10") Integer pageSize){
        PageInfo<Clazz> pageInfo = clazzService.selectPage(clazz,pageNum,pageSize);
        return Result.success(pageInfo);
    }
    @PostMapping("/insert")
    public Result add(@RequestBody Clazz clazz){
        clazzService.add(clazz);
        return Result.success();
    }

    @PutMapping("/update")
    public Result update(@RequestBody Clazz clazz){
        clazzService.update(clazz);
        return Result.success();
    }

    @DeleteMapping("/delete/{classId}")
    public Result delete(@PathVariable Integer classId){
        clazzService.delete(classId);
        return Result.success();
    }

    @DeleteMapping("/deleteBatch")
    public Result deleteBatch(@RequestBody List<Integer> ids){
        clazzService.deleteBatch(ids);
        return Result.success();
    }
}
